package mysql

import (
	"gorm.io/gorm"
	"we-chat-mgr/wechatrpc/wechatrpc"
)

type WeChatMoments struct {
	gorm.Model
	UserId  int64  `gorm:"type:int(11);not null"`
	Content string `gorm:"Type:varchar(500);not null"`
}

func (m *WeChatMoments) WeChatMomentsAdd(db *gorm.DB) error {
	return db.Debug().Create(m).Error
}

func (m *WeChatMoments) DelWechatMoments(db *gorm.DB, id int64) error {
	return db.Debug().Where("user_id=?", id).Delete(m).Error
}
func WeChatMomentsList(db *gorm.DB, in *wechatrpc.WeChatMomentsListRequest) []*wechatrpc.WeChatMomentsList {
	var list []*wechatrpc.WeChatMomentsList
	db.Debug().Model(&WeChatMoments{}).
		Select(
			"we_chat_moments.id we_chat_moments_id",
			"we_chat_moments.content",
		).Scopes(Paginate(int(in.Page), int(in.Size))).Find(&list)
	return list
}
